package com.Login;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import objects.UserItem;

import user.UserControl;

import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * Portlet implementation class PortletLogin
 */
public class PortletLogin extends MVCPortlet {

	private UserControl userControl;
	public PortletLogin() {
		userControl = new UserControl();
	}
	@Override
	public void processAction(ActionRequest actionRequest,
			ActionResponse actionResponse) throws IOException, PortletException {
		// TODO Auto-generated method stub
		super.processAction(actionRequest, actionResponse);
		String username = actionRequest.getParameter("txtUserName");
		String password = actionRequest.getParameter("txtPassword");
		if(username!=null && password!=null){
			UserItem user = userControl.getUser(username, password);
			if(user != null){
				actionRequest.setAttribute("User", user);
				actionResponse.sendRedirect("/login-success/html/loginsuccess/view.jsp");
			}else{
				System.out.println("fails");
				//System.out.println(user.getUser_id());
			}
		}
	}
}
